package com.ruoyi.livesass.api.service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.ruoyi.livesass.api.domain.LbsCloudResource;
import com.ruoyi.livesass.api.mapper.LbsCloudResourceMapper;
import com.ruoyi.livesass.api.pojo.query.LbsCloudResourceQuery;

/**
 * 直播消耗的云资源费用Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class LbsCloudResourceService {
    @Autowired
    private LbsCloudResourceMapper lbsCloudResourceMapper;

    /**
     * 查询直播消耗的云资源费用
     *
     * @param id 直播消耗的云资源费用主键
     * @return 直播消耗的云资源费用
     */
    public LbsCloudResource selectById(Long id) {
        return lbsCloudResourceMapper.selectById(id);
    }

    /**
     * 查询直播消耗的云资源费用列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 直播消耗的云资源费用
     */
    public List<LbsCloudResource> selectList(LbsCloudResourceQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<LbsCloudResource> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
        LocalDateTime createTime = query.getCreateTime();
        if (createTime != null) {
            qw.eq("create_time", createTime);
        }
        String subnameLike = query.getSubnameLike();
        if (!StringUtils.isEmpty(subnameLike)) {
            qw.like("subname", subnameLike);
        }
        
        
        String beginGsrq = query.getBeginGsrq();
        if (!StringUtils.isEmpty(beginGsrq)) {
            qw.ge("gsrq", beginGsrq);
        }
        
        String endGsrq = query.getEndGsrq();
        if (!StringUtils.isEmpty(endGsrq) ) {
            qw.le("gsrq", endGsrq);
        }
        
        
        BigDecimal ecs = query.getEcs();
        if (ecs != null) {
            qw.eq("ecs", ecs);
        }
        BigDecimal sae = query.getSae();
        if (sae != null) {
            qw.eq("sae", sae);
        }
        BigDecimal alb = query.getAlb();
        if (alb != null) {
            qw.eq("alb", alb);
        }
        BigDecimal db = query.getDb();
        if (db != null) {
            qw.eq("db", db);
        }
        BigDecimal redis = query.getRedis();
        if (redis != null) {
            qw.eq("redis", redis);
        }
        BigDecimal cdn = query.getCdn();
        if (cdn != null) {
            qw.eq("cdn", cdn);
        }
        BigDecimal waf = query.getWaf();
        if (waf != null) {
            qw.eq("waf", waf);
        }
        BigDecimal gwll = query.getGwll();
        if (gwll != null) {
            qw.eq("gwll", gwll);
        }
        Long deptZbjId = query.getDeptZbjId();
        if (deptZbjId != null) {
            qw.eq("dept_zbj_id", deptZbjId);
        }
        return lbsCloudResourceMapper.selectList(qw);
    }

    /**
     * 新增直播消耗的云资源费用
     *
     * @param lbsCloudResource 直播消耗的云资源费用
     * @return 结果
     */
    public int insert(LbsCloudResource lbsCloudResource) {
        lbsCloudResource.setDelFlag("0");
        lbsCloudResource.setCreateTime(LocalDateTime.now());
        return lbsCloudResourceMapper.insert(lbsCloudResource);
    }

    /**
     * 修改直播消耗的云资源费用
     *
     * @param lbsCloudResource 直播消耗的云资源费用
     * @return 结果
     */
    public int update(LbsCloudResource lbsCloudResource) {
        return lbsCloudResourceMapper.updateById(lbsCloudResource);
    }

    /**
     * 批量删除直播消耗的云资源费用
     *
     * @param ids 需要删除的直播消耗的云资源费用主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return lbsCloudResourceMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除直播消耗的云资源费用信息
     *
     * @param id 直播消耗的云资源费用主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return lbsCloudResourceMapper.updateDelFlagByIds(ids);
    }
}
